/*
 * athlete.java
 *
 * Created on March 5, 2006, 8:30 PM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */


/**
 *
 * @author Sujal Bista
 */

import java.util.regex.*;

public class athlete 
{
    private String name;
    private String group;
    private String gender;
    private String event;
    private String nandu;
    
    /** Creates a new instance of athlete */
    public athlete() 
    {
        
    }
    
    public void setName(String tName)
    {
        name=tName;
    }
    
    public String getName()
    {
        return name;
    }
    
    public String getGroup()
    {
        return group;
    }
    
    public String getGender()
    {
        return gender;
    }
    
    public String getEvent()
    {
        return event;
    }

    public String getNandu()
    {
        return nandu;
    }
    
    public String getNandu(int i)
    {
        String tempNandu=new String(nandu) ;
        String value="";
        int count=0;
        while(tempNandu.length()!=0)
        {
            
            if(tempNandu.indexOf(",")==-1)
            {
                value=tempNandu;
                tempNandu="";
            }
            else
            {
               value=tempNandu.substring(0, tempNandu.indexOf(","));
               tempNandu=tempNandu.substring(tempNandu.indexOf(",")+1);
            }
            if(count==i)
                break;
            count++;
        }
        return value;
    }
    
    public int getNanduCount()
    {
        String tempNandu=new String(nandu) ;
        int count=0;
        while(tempNandu.length()!=0)
        {
            String value;
            if(tempNandu.indexOf(",")==-1)
            {
                value=tempNandu;
                tempNandu="";
            }
            else
            {
               value=tempNandu.substring(0, tempNandu.indexOf(","));
               tempNandu=tempNandu.substring(tempNandu.indexOf(",")+1);
            }
            count++;
        }
        return count;
    }
    
    //includes sub parts of Nandu
    public int getMovementsCount()
    {
        int count=0;
        for(int i=getNanduCount()-1;i>=0;i--)
        {
            nanduData.nandu nd=globalData.nanduList.find(getNandu(i));
            count+=nd.getTotalMovements();
        }
        return count;
    }
    
    //prints athlete to string
    //has to be in following format
    //[nameLength]:[name]:[nandu]
    public String toString()
    {
        String str;
        str=Integer.toString(name.length())+":";
        str+=name+":";
        str+=nandu;
        return str;
    }
    
    
    //reads athlete from string
    //has to be in following format
    //[nameLength]:[name]:[nandu]
    public void fromString(String str)
    {

        int index,i,j;
        
        //"12:Eric Cartman: 324C+l,312B";
        //read name length
        index=str.indexOf(':');
        int nameLength=Integer.valueOf(str.substring(0, index));
        str=str.substring(index+1);
        
        //read Name
        name=str.substring(0,nameLength);
        str=str.substring(nameLength+1);
       
        //add Nandu
        nandu=str;
    }
        
    public void UnmarshalGroupGenderEvent(String str)
    {
        group=str.substring(0, str.indexOf(' '));
        str=str.substring(str.indexOf(' ')+1);
        
        gender=str.substring(0, str.indexOf(' '));
        str=str.substring(str.indexOf(' ')+1);
        
        event=str;
      
    }
 
    
    
}
